<template>
    <div class="talk">
        <button @click="getLoveTalk">获取一句土味情话</button>
        <ul>
            <li v-for="talk in talkStore.talkList" :key="talk.id">{{ talk.title }}</li>
        </ul>
    </div>
</template>

<script setup lang="ts" name="LoveTalk">
import { useTalkStore } from '@/store/loveTalk';
const talkStore = useTalkStore()
// 通过 store 的 `$subscribe()` 方法侦听 `state` 及其变化
// 通过 store 的 `$subscribe()` 方法侦听 `state` 及其变化
// 通过 store 的 `$subscribe()` 方法侦听 `state` 及其变化
talkStore.$subscribe((mutate:any,state:any)=>{
    console.log('talkStore里面保存的数据发生了变化',typeof(mutate),typeof(state))
    localStorage.setItem('talkList',JSON.stringify(state.talkList))
})
const getLoveTalk = () => {
    talkStore.getLoveTalk()
}
</script>

<style scoped>
.talk {
    background-color: orange;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
}
</style>